/*
 * @(#)PRPAMT201304UV02PatientTransformer.java
 * Date 2013-08-25
 * Version 1.0
 * Author Jim Horner
 * Copyright (c)2012
 */


package us.hornerscorners.lamppost.pix.transformer.hl7;

import javax.enterprise.context.ApplicationScoped;

import javax.inject.Inject;

import org.hl7.v3.PRPAMT201304UV02Patient;
import org.hl7.v3.PRPAMT201304UV02Person;

import us.hornerscorners.lamppost.exception.ServiceActionException;

import us.hornerscorners.lamppost.hl7v3common.transformer.CSTransformer;
import us.hornerscorners.lamppost.hl7v3common.transformer.IITransformer;
import us.hornerscorners.lamppost.hl7v3common.transformer.OtherIDTransformer;
import us.hornerscorners.lamppost.hl7v3common.transformer.PNTransformer;

import us.hornerscorners.lamppost.hl7v3common.utils.HL7Utils;

import us.hornerscorners.lamppost.model.patient.Patient;

import us.hornerscorners.lamppost.transformer.AbstractTransformer;


/**
 *
 * @author jim
 */
@ApplicationScoped
public class PRPAMT201304UV02PatientTransformer
        extends AbstractTransformer<Patient, PRPAMT201304UV02Patient> {

    /** Field description */
    @Inject
    private CSTransformer csTransformer;

    /** Field description */
    @Inject
    private IITransformer iiTransformer;

    /** Field description */
    @Inject
    private OtherIDTransformer otherIDTransformer;

    /** Field description */
    @Inject
    private PNTransformer pnTransformer;

    /**
     * Constructs ...
     *
     */
    public PRPAMT201304UV02PatientTransformer() {
        super();
    }

    /**
     * Method description
     *
     *
     * @param patient
     *
     * @return
     * @throws us.hornerscorners.lamppost.exception.ServiceActionException
     */
    @Override
    public PRPAMT201304UV02Patient transform(Patient patient)
            throws ServiceActionException {

        PRPAMT201304UV02Patient result = new PRPAMT201304UV02Patient();

        result.getClassCode().add("PAT");
        result.setStatusCode(this.csTransformer.transform("active"));

        result.getId().addAll(this.iiTransformer.transform(patient.getIdentifiers()));

        // TODO implement this
        // result.setProviderOrganization(null);

        PRPAMT201304UV02Person prpaPerson = new PRPAMT201304UV02Person();

        prpaPerson.getClassCode().add("PSN");
        prpaPerson.setDeterminerCode("INSTANCE");

        // TODO implement this
        // prpaPerson.getAsCitizen().addAll();

        prpaPerson.getName().addAll(
            this.pnTransformer.transform(patient.getPersonNames()));

        prpaPerson.getAsOtherIDs().addAll(
            this.otherIDTransformer.transform(patient.getOtherIds()));

        result.setPatientPerson(
            HL7Utils.hl7Factory.createPRPAMT201304UV02PatientPatientPerson(prpaPerson));

        return result;
    }
}
